﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;

namespace XPSReaderWPF
{
    /// <summary>
    /// Interaction logic for UCPng.xaml
    /// </summary>
    public partial class UCPng : UserControl
    {
        string _source;
        #region Source
        /// <summary>
        /// Gets or sets the source.
        /// </summary>
        /// <value>The source.</value>
        public string Source
        {
            get { return _source; }
            set { _source = value; }
        }
        #endregion

        bool _rotate;
        #region Rotate
        public bool Rotate
        {
            get { return _rotate; }
            set { _rotate = value; }
        }
        #endregion


        /// <summary>
        /// Initializes a new instance of the <see cref="UCPng"/> class.
        /// </summary>
        /// <param name="btSource">The bt source.</param>
        public UCPng(string btSource, bool rotate)
        {
            InitializeComponent();
            Source = btSource;
            Rotate = rotate;
        }

        /// <summary>
        /// Handles the Loaded event of the UserControl control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            Stream imageStream = new FileStream(Source, FileMode.Open, FileAccess.Read, FileShare.Read);
            BitmapImage myImageStream = new BitmapImage();
            myImageStream.BeginInit();
            myImageStream.StreamSource = imageStream;
            if (Rotate)
                myImageStream.Rotation = Rotation.Rotate270;
            myImageStream.EndInit();
            imagePage.Source = myImageStream;
        }
    }
}
